home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 3531 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: daily-planet.execpc.com!earth!zieman
  2. From: zieman@earth.execpc.com (Glenn Zieman)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Random Number Generation
  5. Date: 21 Feb 1996 03:06:30 GMT
  6. Organization: Exec-PC BBS - Milwaukee, WI
  7. Message-ID: <4ge27m$snj@daily-planet.execpc.com>
  8. References: <199602071623.QAA00075@sable.ox.ac.uk> <Pine.OSF.3.91.960207175121.20357B-100000@hai.hiMolde.no>  <19960207.41F660.11A72@aj050.du.pipex.com> <1100.6613T1273T666@himolde.no> <692.6619T1254T1752@in.net> <4g2bi9$1fls@rs18.hrz.th-darmstadt.de> <19
  9. NNTP-Posting-Host: earth-le1.execpc.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. 960220.7D62838.7EC3@mojaveg.ridgecrest.ca.us>
  13. Organization: Exec-PC
  14. Distribution: 
  15.  
  16. Everett M. Greene (mojaveg@ridgecrest.ca.us) wrote:
  17. : In article <4g2bi9$1fls@rs18.hrz.th-darmstadt.de> kraemer@clri6f.gsi.de (Michael Kraemer) writes:
  18. : > In article <692.6619T1254T1752@in.net>, mave@in.net (John J. Maver, Jr.) writes:
  19. : > > 
  20. : > >         I want to generate a randum number, like BASIC allowed you to do, in
  21. : > > C.  I want a function that I can call with the High and Low numbers and then
  22. : > > have it return a number between them.
  23. : > > 
  24. : > > What I have so far is:
  25. : [snip]
  26. : > >         It doesn't quite work.  Any hints?
  27. : > 
  28. : > Why not sth like that:
  29. : > 
  30. : > #include <stdlib.h>
  31. : > ....
  32. : >    num = ( (float) rand() / 32767E0 ) * ( high - low ) + low; 
  33.  
  34. : In theory, this is a very good suggestion.  In practice, rand() is a
  35. : very poor RNG.  Run any common statistical tests on rand()'s output
  36. : to see.
  37.  
  38. The way that the orginal posting started by using srand() to the time, 
  39. one when using rand() gets a more random number (at least the random 
  40. numbers don't repeat in the same order each time.)
  41.  
  42. --
  43.  ___ 
  44. /   \
  45. |       zieman@execpc.com
  46. |  __  co-syop of EOTU BBS
  47. |   /   (414)633-4021
  48. \__/
  49.   /
  50.  /__
  51.